package com.servlet;

import com.Dao.BookDao;
import com.Dao.BorrowDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "AddBorrowServlet", value = "/AddBorrowServlet")
public class AddBorrowServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        int userNum = Integer.parseInt(request.getParameter("userNum"));
        String userName = request.getParameter("userName");
        int bookId = Integer.parseInt(request.getParameter("bookId"));
        String bookName = request.getParameter("bookName");
        String bookAuthor = request.getParameter("bookAuthor");
        String borrowDate = request.getParameter("borrowDate");
        BorrowDao borrowDao = new BorrowDao();
        BookDao bookDao = new BookDao();
        borrowDao.addBorrow(userNum, userName,bookId, bookName, bookAuthor, borrowDate);
        bookDao.deleteBook1(bookId);
        response.sendRedirect("borrowInfoServlet");

    }
}
